<?php

/**
 * This is the model class for table "{{member}}".
 *
 * The followings are the available columns in table '{{member}}':
 * @property integer $id
 * @property string $serial
 * @property string $name
 * @property string $pass
 * @property string $emal
 * @property string $telephone
 * @property double $amount
 * @property integer $level
 * @property string $gender
 * @property integer $status
 */
class Member extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Member the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return '{{member}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('serial, name, level', 'required'),
            array('level, status', 'numerical', 'integerOnly'=>true),
            array('amount', 'numerical'),
            array('serial, name, emal, telephone', 'length', 'max'=>45),
            array('pass', 'length', 'max'=>32),
            array('gender', 'length', 'max'=>6),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, serial, name, pass, emal, telephone, amount, level, gender, status', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
                'maxMemberId' => array(self::STAT, 'Member', 'id')
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'serial' => 'Serial',
            'name' => 'Name',
            'pass' => 'Pass',
            'emal' => 'Emal',
            'telephone' => 'Telephone',
            'amount' => 'Amount',
            'level' => 'Level',
            'gender' => 'Gender',
            'status' => 'Status',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('serial',$this->serial,true);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('pass',$this->pass,true);
        $criteria->compare('emal',$this->emal,true);
        $criteria->compare('telephone',$this->telephone,true);
        $criteria->compare('amount',$this->amount);
        $criteria->compare('level',$this->level);
        $criteria->compare('gender',$this->gender,true);
        $criteria->compare('status',$this->status);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

    public function getSerial() {
        /* $post=Post::model()->find(array(
                'select'=>'name',
                'condition'=>'postID=:postID',
                'params'=>array(':postID'=>10),
        )); */
        $memeber = $this->with('maxMemberId')->findAll();
        echo '<pre>';
        print_r($memeber);
        //echo $memeber->maxMemberId;
        die('abc');
        return '002';

    }
}